﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Distrackting.BusinessLayer;
using Distrackting.DataLayer;

namespace Distrackting.PresentationLayer
{
    public partial class EditarPerc : System.Web.UI.Page
    {
        Percurso perc;


        protected void Page_Load(object sender, EventArgs e)
        {
            perc = GerirPercursos.getPercurso(new Guid(Request.QueryString["perc"].ToString()));
            TextBoxNome.Text = perc.nome;
            TextBoxDecri.Text = perc.descricao;
            TextBoxDistancia.Text = perc.distancia.ToString();
            TextBoxDuracao.Text = perc.duracao.ToString();
            CalendarData.SelectedDate = System.DateTime.Today;
        }
        protected void Button1_Click(object sender, EventArgs e)
        { 
            perc.nome =TextBoxNome.Text.ToString();
            int duracao = Convert.ToInt32(TextBoxDuracao.Text);
            perc.distancia = (float)Convert.ToSingle(TextBoxDistancia.Text);
            perc.descricao =TextBoxDecri.Text.ToString();
            perc.duracao =Convert.ToInt32(TextBoxDuracao.Text);
            if(DropDownPartida.SelectedIndex != 0)perc.cod_partida = new Guid(DropDownPartida.SelectedValue.ToString());
            if(DropDownChegada.SelectedIndex != 0)perc.cod_chegada = new Guid(DropDownChegada.SelectedValue);
            if(DropDownTipo.SelectedIndex != 0)perc.cod_tipo = new Guid(DropDownTipo.SelectedValue);
            if(DropDownEstado.SelectedIndex != 0)perc.cod_estado = new Guid(DropDownEstado.SelectedValue);
            if(DropDownEpoca.SelectedIndex != 0)perc.cod_epoca = new Guid(DropDownEpoca.SelectedValue);
            if(DropDownEntidade.SelectedIndex != 0)perc.cod_entidade = new Guid(DropDownEntidade.SelectedValue);
            if(DropDownDificuldade.SelectedIndex != 0)perc.cod_dificuldade = new Guid(DropDownDificuldade.SelectedValue);
            if(DropDownDesnivel.SelectedIndex != 0)perc.cod_desnivel = new Guid(DropDownDesnivel.SelectedValue);
            if(DropDownAmbito.SelectedIndex != 0)perc.cod_ambito = new Guid(DropDownAmbito.SelectedValue);
            perc.data = CalendarData.SelectedDate;
            GerirPercursos.actualizaPercurso(perc);
        }

        protected void CalendarData_SelectionChanged(object sender, EventArgs e)
        {
            TextBoxData.Text = CalendarData.SelectedDate.ToShortDateString();

        }


        
    }
}
